Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(), //day
        "h+": this.getHours(), //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1,
        (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
};

/**
 * 判断是否为整数
 * @param obj
 * @return {boolean}
 */
function isInteger(obj) {
    return Math.floor(obj) === obj
}

/**
 * 判断是否为数字
 * @param num
 * @return {boolean}
 */
function isNumber(num) {
    var number = +num;

    if ((number - number) !== 0) {
        // Discard Infinity and NaN
        return false;
    }

    if (number === num) {
        return true;
    }

    if (typeof num === 'string') {
        // String parsed, both a non-empty whitespace string and an empty string
        // will have been coerced to 0. If 0 trim the string and see if its empty.
        if (number === 0 && num.trim() === '') {
            return false;
        }
        return true;
    }
    return false;
}

/**
 * 保留两位小数
 * @param num
 * @param isRate 是否为率
 * @return {*}
 */
function parseNum(num, isRate) {
    if (isNumber(num)) {
        if (isInteger(num)) {
            if (isRate) {
                return (parseFloat(num) * 100).toFixed(2) + '%';
            } else {
                return num;
            }
        } else {
            if (isRate) {
                return (parseFloat(num) * 100).toFixed(2) + '%';
            } else {
                return parseFloat(num).toFixed(2);
            }
        }
    } else {
        return num;
    }
}